﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.Entity;
using System.Data.Entity.ModelConfiguration.Conventions;
using System.Data.Entity.Infrastructure;
using System.ComponentModel.DataAnnotations;


namespace MasterSheetManager.Models.Utl
{
    public class DB : DbContext
    {
        public DbSet<Arrival> Arrival { get; set; }
        public DbSet<Company> Company { get; set; }
        public DbSet<CompanyRelationship> CompanyRelationship { get; set; }
        public DbSet<Deal> Deal { get; set; }
        public DbSet<Package> Package { get; set; }
        public DbSet<PackageType> PackageType { get; set; }
        public DbSet<Participant> Participant { get; set; }
        public DbSet<ParticipantType> ParticipantType { get; set; }

        public DbSet<EmployeeRole> EmployeeRoles { get; set; }
        public DbSet<Role> Roles { get; set; }
        public DbSet<Department> Departments { get; set; }
        public DbSet<ExpLevel> ExpLevels { get; set; }
        public DbSet<SimulatorConfig> SimulatorConfig { get; set; }

        public DbSet<Member> Members { get; set; }

        public DB(string connection = null)
        {
            Database.SetInitializer<DB>(null);
            if (!string.IsNullOrEmpty(connection))
            {
                this.Database.Connection.ConnectionString = connection;
            }

            this.Configuration.LazyLoadingEnabled = true;
            this.Configuration.ValidateOnSaveEnabled = false;
        }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
        }

        public void Detach(object entity)
        {
            ((IObjectContextAdapter)this).ObjectContext.Detach(entity);
        }
    }

    public class DBInitializer : DropCreateDatabaseIfModelChanges<DB>
    {
        protected override void Seed(DB context)
        {

        }
    }
}